﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Karno8
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }
        private Karno k;
        private void btnResult_Click(object sender, EventArgs e)
        {            
            k = new Karno(8);
            k.Cell(0, byte.Parse(txt0.Text));
            k.Cell(1, byte.Parse(txt1.Text));
            k.Cell(2, byte.Parse(txt2.Text));
            k.Cell(3, byte.Parse(txt3.Text));
            k.Cell(4, byte.Parse(txt4.Text));
            k.Cell(5, byte.Parse(txt5.Text));
            k.Cell(6, byte.Parse(txt6.Text));
            k.Cell(7, byte.Parse(txt7.Text));            
            
            txtResult.Text = k.Optimized();
        }

        private void btnEnter_Click(object sender, EventArgs e)
        {
            try
            {
                txt0.Text = txt1.Text = txt2.Text = txt3.Text = txt4.Text = txt5.Text = txt6.Text = txt7.Text = "0";
                char[] ch = new char[1];
                ch[0] = '+';
                txtInput.Text = txtInput.Text.ToUpper();
                string[] st = txtInput.Text.Split(ch);
                for (byte i = 0; i < st.Length; i++)
                {
                    switch (st[i])
                    {
                        case "|A|B|C": txt0.Text = "1"; break;
                        case "|A|BC": txt1.Text = "1"; break;
                        case "|AB|C": txt2.Text = "1"; break;
                        case "|ABC": txt3.Text = "1"; break;
                        case "A|B|C": txt4.Text = "1"; break;
                        case "A|BC": txt5.Text = "1"; break;
                        case "AB|C": txt6.Text = "1"; break;
                        case "ABC": txt7.Text = "1"; break;
                        case "A": txt4.Text = "1"; txt5.Text = "1"; txt6.Text = "1"; txt7.Text = "1"; break;
                        case "|A": txt0.Text = "1"; txt1.Text = "1"; txt2.Text = "1"; txt3.Text = "1"; break;
                        case "B": txt2.Text = "1"; txt3.Text = "1"; txt6.Text = "1"; txt7.Text = "1"; break;
                        case "|B": txt0.Text = "1"; txt1.Text = "1"; txt4.Text = "1"; txt5.Text = "1"; break;
                        case "C": txt1.Text = "1"; txt3.Text = "1"; txt5.Text = "1"; txt7.Text = "1"; break;
                        case "|C": txt0.Text = "1"; txt2.Text = "1"; txt4.Text = "1"; txt6.Text = "1"; break;
                        case "AB": txt6.Text = "1"; txt7.Text = "1"; break;
                        case "A|B": txt4.Text = "1"; txt5.Text = "1"; break;
                        case "AC": txt5.Text = "1"; txt7.Text = "1"; break;
                        case "A|C": txt4.Text = "1"; txt6.Text = "1"; break;
                        case "|AB": txt2.Text = "1"; txt3.Text = "1"; break;
                        case "|A|B": txt0.Text = "1"; txt1.Text = "1"; break;
                        case "|AC": txt1.Text = "1"; txt3.Text = "1"; break;
                        case "|A|C": txt0.Text = "1"; txt2.Text = "1"; break;
                        case "B|C": txt2.Text = "1"; txt6.Text = "1"; break;
                        case "BC": txt3.Text = "1"; txt7.Text = "1"; break;
                        case "|BC": txt1.Text = "1"; txt5.Text = "1"; break;
                        case "|B|C": txt0.Text = "1"; txt4.Text = "1"; break;
                        case "0": txt0.Text = txt1.Text = txt2.Text = txt3.Text = txt4.Text = txt5.Text = txt6.Text = txt7.Text = "0"; break;
                        case "1": txt0.Text = txt1.Text = txt2.Text = txt3.Text = txt4.Text = txt5.Text = txt6.Text = txt7.Text = "1"; break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {

        }
    }
}
